<!DOCTYPE html>
<?php session_start(); ?>
<html>
<head>
	<title>AddBookToDB</title>
	<meta charset="UTF-8" />
</head>
<body>
<?php
	if(!isset($_SESSION["session_username"]))
    {
    	header("location:index.php");
    	exit();
	}
	
	$bkname = $_POST["newbkname"];
	include_once "Book.php";
	$flag = Book::noBook($bkname);
	if($flag == false)
	{
?>
<h1>该书以存在，即将跳转</h1>
<?php
		header("Refresh:3;url='index.php'");
    	exit();
	}
	$bkc = $_POST["newbkintro"];
	$bkt = $_POST["newbktag"];
	$tmpimgname;
	if(is_uploaded_file($_FILES["newbkface"]["tmp_name"]))
	{
		$tmpimgname = $_FILES["newbkface"]["name"];
		move_uploaded_file($_FILES["newbkface"]["tmp_name"],iconv("utf-8","gb2312","image/$tmpimgname"));
	}
	// echo $tmpimgname;
	// echo "image/$tmpimgname";
	Book::addBook($bkname,"image/$tmpimgname",$bkc,$bkt);
	header("location:ShowBook.php?bookname=$bkname");
?>
</body>
</html>